
#include "font.h"

const font_t font_4x7_led[] PROGMEM = {
        '.', 1, 7, 0x00,0x00,0x00,0x00,0x00,0x00,0x80,
        '$', 4, 7, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,  //place holder
        ' ', 1, 7, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        '0',  4, 7, 0xF0,0x90,0x90,0x90,0x90,0x90,0xF0,
        '1',  4, 7, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,
        '2',  4, 7, 0xF0,0x10,0x10,0xF0,0x80,0x80,0xF0,
        '3',  4, 7, 0xF0,0x10,0x10,0xF0,0x10,0x10,0xF0,
        '4',  4, 7, 0x90,0x90,0x90,0xF0,0x10,0x10,0x10,
        '5',  4, 7, 0xF0,0x80,0x80,0xF0,0x10,0x10,0xF0,
        '6',  4, 7, 0xF0,0x80,0x80,0xF0,0x90,0x90,0xF0,
        '7',  4, 7, 0xF0,0x10,0x10,0x10,0x10,0x10,0x10,
        '8',  4, 7, 0xF0,0x90,0x90,0xF0,0x90,0x90,0xF0,
        '9',  4, 7, 0xF0,0x90,0x90,0xF0,0x10,0x10,0xF0,
        ':',  1, 7, 0x00,0x00,0x80,0x00,0x80,0x00,0x00,
        '%',  4, 7, 0xC0,0xC0,0x10,0x20,0x40,0xB0,0x30,
        '/',  2, 7, 0x00,0x00,0x40,0xC0,0x80,0x00,0x00,
        '-',  2, 7 ,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,  //-
        0xE0, 4, 7, 0x80,0x60,0x90,0x80,0x80,0x90,0x60, // ℃
        0 // here is the end flag.
};


const font_t font_4x7_aria[] PROGMEM = {
        '.', 1, 7, 0x00,0x00,0x00,0x00,0x00,0x00,0x80,
        '$', 4, 7, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,  //place holder
        ' ', 1, 7, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        '0',  4, 7, 0x60,0x90,0x90,0x90,0x90,0x90,0x60,
        '1',  4, 7, 0x20,0x60,0x20,0x20,0x20,0x20,0x20,
        '2',  4, 7, 0x60,0x90,0x10,0x20,0x40,0x80,0xF0,
        '3',  4, 7, 0x60,0x90,0x10,0xE0,0x10,0x90,0x60,
        '4',  4, 7, 0x20,0x60,0xA0,0xA0,0xF0,0x20,0x20,
        '5',  4, 7, 0xF0,0x80,0x80,0xF0,0x10,0x90,0x60,
        '6',  4, 7, 0x60,0x90,0x80,0xE0,0x90,0x90,0x60,
        '7',  4, 7, 0xF0,0x90,0x20,0x40,0x40,0x40,0x40,
        '8',  4, 7, 0x60,0x90,0x90,0x60,0x90,0x90,0x60,
        '9',  4, 7, 0x60,0x90,0x90,0x70,0x10,0x90,0x60,
        ':',  1, 7, 0x00,0x00,0x80,0x00,0x80,0x00,0x00,
        '%',  4, 7, 0xC0,0xC0,0x10,0x20,0x40,0xB0,0x30,
        '/',  2, 7, 0x00,0x00,0x40,0xC0,0x80,0x00,0x00,
        '-',  2, 7 ,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,  //-
        0xE0, 4, 7, 0x80,0x60,0x90,0x80,0x80,0x90,0x60, // ℃
        0 // here is the end flag.
};

font_t* font_get_font(uint8_t font_type){
    return font_type == FT_LED ? font_4x7_led : font_4x7_aria;
}


uint8_t font_get_glyph(const font_t* font, char encoding, glyph_t* glyph){
        glyph_t* pos =(glyph_t *) font;
        char ch = 0;
        do{
                ch = pgm_read_byte(pos);
                if(ch == encoding) {
                        memcpy_P(glyph, pos, sizeof(glyph_t));
                        return 0;
                } else {
                        pos++;
                }
        }while(ch != 0);

        return ERR_GLYPH_NOT_FOUND;
}
